<!DOCTYPE HTML>
<html lang="cn" class="light" dir="ltr">
    <head>
        <!-- Book generated using mdBook -->
        <meta charset="UTF-8">
        <title>三角函数 - 计算机图形学基础</title>


        <!-- Custom HTML head -->
        
        <meta name="description" content="Drawing on an impressive roster of experts in the field, Fundamentals of Computer Graphics, Fifth Edition offers an ideal resource for computer course curricula as well as a user-friendly personal or professional reference">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="theme-color" content="#ffffff">

        <link rel="icon" href="favicon.svg">
        <link rel="shortcut icon" href="favicon.png">
        <link rel="stylesheet" href="css/variables.css">
        <link rel="stylesheet" href="css/general.css">
        <link rel="stylesheet" href="css/chrome.css">
        <link rel="stylesheet" href="css/print.css" media="print">

        <!-- Fonts -->
        <link rel="stylesheet" href="FontAwesome/css/font-awesome.css">
        <link rel="stylesheet" href="fonts/fonts.css">

        <!-- Highlight.js Stylesheets -->
        <link rel="stylesheet" href="highlight.css">
        <link rel="stylesheet" href="tomorrow-night.css">
        <link rel="stylesheet" href="ayu-highlight.css">

        <!-- Custom theme stylesheets -->

        <!-- MathJax -->
        <script async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    </head>
    <body class="sidebar-visible no-js">
    <div id="body-container">
        <!-- Provide site root to javascript -->
        <script>
            var path_to_root = "";
            var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
        </script>

        <!-- Work around some values being stored in localStorage wrapped in quotes -->
        <script>
            try {
                var theme = localStorage.getItem('mdbook-theme');
                var sidebar = localStorage.getItem('mdbook-sidebar');

                if (theme.startsWith('"') && theme.endsWith('"')) {
                    localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
                }

                if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
                    localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
                }
            } catch (e) { }
        </script>

        <!-- Set the theme before any content is loaded, prevents flash -->
        <script>
            var theme;
            try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
            if (theme === null || theme === undefined) { theme = default_theme; }
            var html = document.querySelector('html');
            html.classList.remove('light')
            html.classList.add(theme);
            var body = document.querySelector('body');
            body.classList.remove('no-js')
            body.classList.add('js');
        </script>

        <input type="checkbox" id="sidebar-toggle-anchor" class="hidden">

        <!-- Hide / unhide sidebar before it is displayed -->
        <script>
            var body = document.querySelector('body');
            var sidebar = null;
            var sidebar_toggle = document.getElementById("sidebar-toggle-anchor");
            if (document.body.clientWidth >= 1080) {
                try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
                sidebar = sidebar || 'visible';
            } else {
                sidebar = 'hidden';
            }
            sidebar_toggle.checked = sidebar === 'visible';
            body.classList.remove('sidebar-visible');
            body.classList.add("sidebar-" + sidebar);
        </script>

        <nav id="sidebar" class="sidebar" aria-label="Table of contents">
            <div class="sidebar-scrollbox">
                <ol class="chapter"><li class="chapter-item expanded affix "><a href="chapter_0.html">前言</a></li><li class="chapter-item expanded affix "><a href="chapter_0_1.html">致谢</a></li><li class="chapter-item expanded affix "><a href="chapter_0_2.html">作者</a></li><li class="chapter-item expanded "><a href="chapter_1.html"><strong aria-hidden="true">1.</strong> 介绍</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="chapter_1_1.html"><strong aria-hidden="true">1.1.</strong> 图形学领域</a></li><li class="chapter-item expanded "><a href="chapter_1_2.html"><strong aria-hidden="true">1.2.</strong> 主要应用</a></li><li class="chapter-item expanded "><a href="chapter_1_3.html"><strong aria-hidden="true">1.3.</strong> 图形API</a></li><li class="chapter-item expanded "><a href="chapter_1_4.html"><strong aria-hidden="true">1.4.</strong> 图形管道</a></li><li class="chapter-item expanded "><a href="chapter_1_5.html"><strong aria-hidden="true">1.5.</strong> 数值问题</a></li><li class="chapter-item expanded "><a href="chapter_1_6.html"><strong aria-hidden="true">1.6.</strong> 效率</a></li><li class="chapter-item expanded "><a href="chapter_1_7.html"><strong aria-hidden="true">1.7.</strong> 图形程序设计和编码</a></li></ol></li><li class="chapter-item expanded "><a href="chapter_2.html"><strong aria-hidden="true">2.</strong> 各种数学知识</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="chapter_2_1.html"><strong aria-hidden="true">2.1.</strong> 集合和映射</a></li><li class="chapter-item expanded "><a href="chapter_2_2.html"><strong aria-hidden="true">2.2.</strong> 二次方程求解</a></li><li class="chapter-item expanded "><a href="chapter_2_3.html" class="active"><strong aria-hidden="true">2.3.</strong> 三角函数</a></li><li class="chapter-item expanded "><a href="chapter_2_4.html"><strong aria-hidden="true">2.4.</strong> 向量</a></li><li class="chapter-item expanded "><a href="chapter_2_5.html"><strong aria-hidden="true">2.5.</strong> 曲线和曲面</a></li><li class="chapter-item expanded "><a href="chapter_2_6.html"><strong aria-hidden="true">2.6.</strong> 线性插值</a></li><li class="chapter-item expanded "><a href="chapter_2_7.html"><strong aria-hidden="true">2.7.</strong> 三角形</a></li></ol></li><li class="chapter-item expanded "><a href="chapter_3.html"><strong aria-hidden="true">3.</strong> 光栅图像</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="chapter_3_1.html"><strong aria-hidden="true">3.1.</strong> 光栅设备</a></li><li class="chapter-item expanded "><a href="chapter_3_2.html"><strong aria-hidden="true">3.2.</strong> 图像、像素和几何学</a></li><li class="chapter-item expanded "><a href="chapter_3_3.html"><strong aria-hidden="true">3.3.</strong> RGB颜色</a></li><li class="chapter-item expanded "><a href="chapter_3_4.html"><strong aria-hidden="true">3.4.</strong> 阿尔法合成</a></li><li class="chapter-item expanded "><a href="chapter_3_5.html"><strong aria-hidden="true">3.5.</strong> FAQ</a></li><li class="chapter-item expanded "><a href="chapter_3_6.html"><strong aria-hidden="true">3.6.</strong> 练习</a></li></ol></li></ol>
            </div>
            <div id="sidebar-resize-handle" class="sidebar-resize-handle">
                <div class="sidebar-resize-indicator"></div>
            </div>
        </nav>

        <!-- Track and set sidebar scroll position -->
        <script>
            var sidebarScrollbox = document.querySelector('#sidebar .sidebar-scrollbox');
            sidebarScrollbox.addEventListener('click', function(e) {
                if (e.target.tagName === 'A') {
                    sessionStorage.setItem('sidebar-scroll', sidebarScrollbox.scrollTop);
                }
            }, { passive: true });
            var sidebarScrollTop = sessionStorage.getItem('sidebar-scroll');
            sessionStorage.removeItem('sidebar-scroll');
            if (sidebarScrollTop) {
                // preserve sidebar scroll position when navigating via links within sidebar
                sidebarScrollbox.scrollTop = sidebarScrollTop;
            } else {
                // scroll sidebar to current active section when navigating via "next/previous chapter" buttons
                var activeSection = document.querySelector('#sidebar .active');
                if (activeSection) {
                    activeSection.scrollIntoView({ block: 'center' });
                }
            }
        </script>

        <div id="page-wrapper" class="page-wrapper">

            <div class="page">
                                <div id="menu-bar-hover-placeholder"></div>
                <div id="menu-bar" class="menu-bar sticky">
                    <div class="left-buttons">
                        <label id="sidebar-toggle" class="icon-button" for="sidebar-toggle-anchor" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
                            <i class="fa fa-bars"></i>
                        </label>
                        <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
                            <i class="fa fa-paint-brush"></i>
                        </button>
                        <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
                            <li role="none"><button role="menuitem" class="theme" id="light">Light</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
                            <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
                        </ul>
                        <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
                            <i class="fa fa-search"></i>
                        </button>
                    </div>

                    <h1 class="menu-title">计算机图形学基础</h1>

                    <div class="right-buttons">
                        <a href="print.html" title="Print this book" aria-label="Print this book">
                            <i id="print-button" class="fa fa-print"></i>
                        </a>

                    </div>
                </div>

                <div id="search-wrapper" class="hidden">
                    <form id="searchbar-outer" class="searchbar-outer">
                        <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
                    </form>
                    <div id="searchresults-outer" class="searchresults-outer hidden">
                        <div id="searchresults-header" class="searchresults-header"></div>
                        <ul id="searchresults">
                        </ul>
                    </div>
                </div>

                <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
                <script>
                    document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
                    document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
                    Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
                        link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
                    });
                </script>

                <div id="content" class="content">
                    <main>
                        <h1 id="三角函数"><a class="header" href="#三角函数">三角函数</a></h1>
<p>  在图形学中，我们在许多情况下使用基本三角函数。通常情况下，它不怎么花哨，但是经常有助于记住基本定义。</p>
<h2 id="角度"><a class="header" href="#角度">角度</a></h2>
<p>  尽管我们认为角度是理所当然的，但我们应该回到它们的定义，以便我们可以将角度的概念延伸到球体上。角度是在两条半线（从原点出发的无限射线）或方向之间形成的，并且必须用一些约定来决定它们之间产生的角度的两种可能性，如图2.6所示。角度是由它在单位圆上切出的弧段的长度来定义的。一个常见的约定是使用较小的弧长，角的符号由指定两条半线的顺序来决定。使用该约定，所有角度都在 \([-\pi, \pi]\) 范围内。</p>
<p><img src="./img/2.6.png" alt="2.6" /></p>
<p><strong>图2.6</strong>：两条半线将单位圆切割成两条弧。任意一条弧线的长度都是这两条半线“之间”的有效角度。我们可以使用较小长度是角度的约定，或者两条半线按一定顺序指定，确定角度 \(\phi\) 的弧是从第一条半线到第二条半线逆时针扫过的弧。</p>
<p>  这些角度中的每一个都是被两个方向“切割”的单位圆的弧长。因为单位圆的边缘是 \(2\pi\)，所以两个可能的角度总和为 \(2\pi\)。这些弧长的单位是弧度。另一个常见的单位是度数，圆的周长是 \(360^\circ\)。因此，一个弧度为 \(\pi\) 的角的度度是 \(180^\circ\)，通常表示为 \(180^\circ\)。度数和弧度之间的转换是</p>
<p>\[
Degrees =\frac{180}{\pi} radians;\\
Radians =\frac{\pi}{180} degrees.
\]</p>
<h2 id="三角函数-1"><a class="header" href="#三角函数-1">三角函数</a></h2>
<p>  给出一个边长为 \(a\)、\(o\)、\(h\) 的直角三角形，其中 \(h\) 是最长边的长度（总是与直角相对），或叫斜边，勾股定理描述了一种重要的关系：</p>
<p>\[
a^2+o^2=h^2
\]</p>
<p>  你可以从图2.7中看到这一点，大正方形的面积为 \((a+o)^2\)，四个三角形的面积合计为 \(2a0\)，中心正方形的面积为 \(h^2\)。</p>
<p><img src="./img/2.7.png" alt="2.7" /></p>
<p><strong>图2.7</strong>：勾股定理的几何证明。</p>
<p>  由于三角形和内部方块均匀地细分了较大的正方形，所以我们可以很容易地取得如下形式 \(2ao+h^2=(a+o)^2\)。我们定义了 \(\phi\)，以及其他基于比值的三角表达式：</p>
<p>\[
\begin{aligned}
\sin \phi &amp; \equiv o / h \\
\csc \phi &amp; \equiv h / o \\
\cos \phi &amp; \equiv a / h \\
\sec \phi &amp; \equiv h / a \\
\tan \phi &amp; \equiv o / a \\
\cot \phi &amp; \equiv a / o
\end{aligned}
\]</p>
<p>  这些定义允许我们建立极坐标，其中一个点被编码为与原点的距离与 \(x\) 正半轴带符号的角度（图2.8）。请注意，角度的范围是 \(\phi\in(-\pi,\pi]\)，正数角是从 \(x\) 轴正半轴逆时针方向旋转取得的。逆时针方向映射到正数的这个约定是任意的，但它被应用于图形学很多场景中，因此值得将其记忆。</p>
<p><img src="./img/2.8.png" alt="2.8" /></p>
<p><strong>图2.8</strong>：点 \((x_a,y_a)\) 的极坐标为 \((r_a,\phi_a)=(2,\frac{\pi}{3})\)。</p>
<p>  三角函数是周期性的，可以接受任何角度作为参数。例如，\(\sin(A) = \sin(A + 2\pi)\)。这意味着当与 \(\mathbb{R}\) 域考虑时，这些函数是不可逆的。这个问题可以通过限制标准反函数的范围来避免。这在几乎所有现代数学库中都是以标准方式进行的（例如，Plauger（1991））。域和范围是</p>
<p>\[
\begin{equation}
\begin{aligned}
&amp;\operatorname{asin}:[-1,1] \mapsto[-\pi / 2, \pi / 2] \\
&amp;\operatorname{acos}:[-1,1] \mapsto[0, \pi] \\
&amp;\operatorname{atan}: \mathbb{R} \mapsto[-\pi / 2, \pi / 2] \\
&amp;\operatorname{atan} 2: \mathbb{R}^{2} \mapsto[-\pi, \pi]
\end{aligned}
\end{equation}
\]</p>
<p>  最后一个函数 \(\operatorname{atan} 2(s,c)\) 通常非常有用。它采用与 \(\sin A\) 成比例的 \(s\) 值以及与 \(\cos A\) 成比例的 \(c\) 值，两者具有相同的因子，最后返回 \(A\)。假定因子为正数。一种看法是它返回了二维笛卡尔点 \((c,s)\) 在极坐标中的角度（图2.9）。</p>
<p><img src="./img/2.9.png" alt="2.9" /></p>
<p><strong>图2.9</strong>：函数 \(\operatorname{atan} 2(s,c)\) 返回 \(A\) 的角度，这通常在图形学中非常有用。</p>
<h2 id="有用的恒等式"><a class="header" href="#有用的恒等式">有用的恒等式</a></h2>
<p>  本节未经推导列出了各种有用的三角恒等式。</p>
<p>  转换恒等式：</p>
<p>\[
\begin{aligned}
\sin (-A) &amp;=-\sin A \\
\cos (-A) &amp;=\cos A \\
\tan (-A) &amp;=-\tan A \\
\sin (\pi / 2-A) &amp;=\cos A \\
\cos (\pi / 2-A) &amp;=\sin A \\
\tan (\pi / 2-A) &amp;=\cot A
\end{aligned}
\]</p>
<p>  毕达哥拉斯恒等式：</p>
<p>\[
\begin{array}{r}
\sin ^{2} A+\cos ^{2} A=1 \\
\sec ^{2} A-\tan ^{2} A=1 \\
\csc ^{2} A-\cot ^{2} A=1
\end{array}
\]</p>
<p>  加减法恒等式：</p>
<p>\[
\begin{aligned}
\sin (A+B) &amp;=\sin A \cos B+\sin B \cos A \\
\sin (A-B) &amp;=\sin A \cos B-\sin B \cos A \\
\sin (2 A) &amp;=2 \sin A \cos A \\
\cos (A+B) &amp;=\cos A \cos B-\sin A \sin B \\
\cos (A-B) &amp;=\cos A \cos B+\sin A \sin B \\
\cos (2 A) &amp;=\cos ^{2} A-\sin ^{2} A
\end{aligned}
\]</p>
<p>\[
\begin{aligned}
\tan (A+B) &amp;=\frac{\tan A+\tan _{B}}{1-\tan A \tan B} \\
\tan (A-B) &amp;=\frac{\tan A-\tan B}{1+\tan A \tan B} \\
\tan (2 A) &amp;=\frac{2 \tan A}{1-\tan A}
\end{aligned}
\]</p>
<p>  半角恒等式：</p>
<p>\[
\begin{aligned}
&amp;\sin ^{2}(A / 2)=(1-\cos A) / 2 \\
&amp;\cos ^{2}(A / 2)=(1+\cos A) / 2
\end{aligned}
\]</p>
<p>  乘法恒等式：</p>
<p>\[
\begin{aligned}
&amp;\sin A \sin B=-(\cos (A+B)-\cos (A-B)) / 2 \\
&amp;\sin A \cos B=(\sin (A+B)+\sin (A-B)) / 2 \\
&amp;\cos A \cos B=(\cos (A+B)+\cos (A-B)) / 2
\end{aligned}
\]</p>
<p>  以下恒等式适用于边长为 \(a\)、\(b\) 和 \(c\) 的任意三角形，每边相对的角度分别为 A、B、C（图 2.10），</p>
<p><img src="./img/2.10.png" alt="2.10" /></p>
<p><strong>图2.10</strong>：几何的三角定律。</p>
<p>\[
\begin{aligned}
\frac{\sin A}{a}=\frac{\sin B}{b}=\frac{\sin C}{c}\quad &amp;\mbox{（正弦定理）}\\
c^{2}=a^{2}+b^{2}-2 a b \cos C\quad &amp;\mbox{（余弦定律）}\\
\frac{a+b}{a-b}=\frac{\tan \left(\frac{A+B}{2}\right)}{\tan \left(\frac{A-B}{2}\right)}\quad &amp;\mbox{（切线定律）}
\end{aligned}
\]</p>
<p>  三角形的面积也可以根据这些边长计算：</p>
<p>\[
\text { Triangle area }=\frac{1}{4} \sqrt{(a+b+c)(-a+b+c)(a-b+c)(a+b-c)} .
\]</p>

                    </main>

                    <nav class="nav-wrapper" aria-label="Page navigation">
                        <!-- Mobile navigation buttons -->
                            <a rel="prev" href="chapter_2_2.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                                <i class="fa fa-angle-left"></i>
                            </a>

                            <a rel="next prefetch" href="chapter_2_4.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                                <i class="fa fa-angle-right"></i>
                            </a>

                        <div style="clear: both"></div>
                    </nav>
                </div>
            </div>

            <nav class="nav-wide-wrapper" aria-label="Page navigation">
                    <a rel="prev" href="chapter_2_2.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
                        <i class="fa fa-angle-left"></i>
                    </a>

                    <a rel="next prefetch" href="chapter_2_4.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
                        <i class="fa fa-angle-right"></i>
                    </a>
            </nav>

        </div>

        <!-- Livereload script (if served using the cli tool) -->
        <script>
            const wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
            const wsAddress = wsProtocol + "//" + location.host + "/" + "__livereload";
            const socket = new WebSocket(wsAddress);
            socket.onmessage = function (event) {
                if (event.data === "reload") {
                    socket.close();
                    location.reload();
                }
            };

            window.onbeforeunload = function() {
                socket.close();
            }
        </script>



        <script>
            window.playground_copyable = true;
        </script>


        <script src="elasticlunr.min.js"></script>
        <script src="mark.min.js"></script>
        <script src="searcher.js"></script>

        <script src="clipboard.min.js"></script>
        <script src="highlight.js"></script>
        <script src="book.js"></script>

        <!-- Custom JS scripts -->


    </div>
    </body>
</html>
